package com.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
import java.net.CookieHandler;
import java.util.ArrayList;
import java.util.Collection;

/**
 * Created by dpeng on 2015/8/31.
 */
public class Iterator extends SimpleTagSupport {

    private String collection;
    private String item;

    public String getCollection() {
        return collection;
    }

    public void setCollection(String collection) {
        this.collection = collection;
    }

    public String getItem() {
        return item;
    }

    public void setItem(String item) {
        this.item = item;
    }

    //遍历集合中的元素
    @Override
    public void doTag() throws JspException, IOException {
        Collection itemList = (Collection) getJspContext().getAttribute(collection);
        for(Object o : itemList) {
            getJspContext().setAttribute(item, o);
            //执行标签包裹里的功能
            getJspBody().invoke(null);
        }
    }
}
